.TH std::abort 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::abort \- std::abort

.SH Synopsis
   Defined in header <cstdlib>
   void abort();                        \fI(until C++11)\fP
   [[noreturn]] void abort() noexcept;  \fI(since C++11)\fP

   Causes abnormal program termination unless SIGABRT is being caught by a signal
   handler passed to std::signal and the handler does not return.

   Destructors of variables with automatic
   , thread local
   \fI(since C++11)\fP and static storage durations are not called. Functions registered with
   std::atexit()
   and std::at_quick_exit
   \fI(since C++11)\fP are also not called. Whether open resources such as files are closed
   is implementation defined. An implementation defined status is returned to the host
   environment that indicates unsuccessful execution.

.SH Parameters

   \fI(none)\fP

.SH Return value

   None because it does not return.

.SH Exceptions

   Throws nothing.

.SH Notes

   POSIX specifies that the abort() function overrides blocking or ignoring the SIGABRT
   signal.

   Some compiler intrinsics, e.g. __builtin_trap (gcc, clang, and icc) or
   __fastfail/__debugbreak (msvc), can be used to terminate the program as fast as
   possible.

.SH Example


// Run this code

 #include <csignal>
 #include <cstdlib>
 #include <iostream>

 class Tester
 {
 public:
     Tester()  { std::cout << "Tester ctor\\n"; }
     ~Tester() { std::cout << "Tester dtor\\n"; }
 };

 Tester static_tester; // Destructor not called

 void signal_handler(int signal)
 {
     if (signal == SIGABRT)
         std::cerr << "SIGABRT received\\n";
     else
         std::cerr << "Unexpected signal " << signal << " received\\n";
     std::_Exit(EXIT_FAILURE);
 }

 int main()
 {
     Tester automatic_tester; // Destructor not called

     // Setup handler
     auto previous_handler = std::signal(SIGABRT, signal_handler);
     if (previous_handler == SIG_ERR)
     {
         std::cerr << "Setup failed\\n";
         return EXIT_FAILURE;
     }

     std::abort(); // Raise SIGABRT
     std::cout << "This code is unreachable\\n";
 }

.SH Output:

 Tester ctor
 Tester ctor
 SIGABRT received

.SH See also

   exit          causes normal program termination with cleaning up
                 \fI(function)\fP
   atexit        registers a function to be called on std::exit() invocation
                 \fI(function)\fP
   quick_exit    causes quick program termination without completely cleaning up
   \fI(C++11)\fP       \fI(function)\fP
   at_quick_exit registers a function to be called on std::quick_exit invocation
   \fI(C++11)\fP       \fI(function)\fP
   signal        sets a signal handler for particular signal
                 \fI(function)\fP
   terminate     function called when exception handling fails
                 \fI(function)\fP
   C documentation for
   abort
